package com.fleapx.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.fleapx.mapper.UserMapper;
import com.fleapx.pojo.User;
import com.fleapx.service.UserService;

@Service
public class UserServiceImpl implements UserService{
	@Autowired
	public UserMapper userMapper;
	@Override
	public void addUser(User user){
		userMapper.addUser(user);
	}

	/**
	 * 事务测试
	 * 注意：(1)有@Transactional注解的方法，方法内部不可以做切换数据库操作
	 *      (2)在同一个service其他方法调用带@Transactional的方法，事务不起作用，（比如：在本类中使用testProcess调用process()）
	 *         可以用其他service中调用带@Transactional注解的方法，或在controller中调用.
	 * @return
	 */
	//propagation 传播行为 isolation 隔离级别  rollbackFor 回滚规则

	@Override
	public List<User> getList(){
		System.out.println(userMapper);
		return userMapper.getList();
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT,timeout=36000,rollbackFor=Exception.class)
	public void update(User user) {
		// TODO Auto-generated method stub
		System.out.println(userMapper.getUserBykey(1));
		userMapper.update(user);
	}

	@Override
	public User getUserBykey(int id) {
		// TODO Auto-generated method stub
		return userMapper.getUserBykey(id);
	}

	@Override
	public void delete(int userId) {
		// TODO Auto-generated method stub
		userMapper.delete(userId);
	}

	@Override
	public void copyLastData(){
		userMapper.copyLastData();
	}

	
	
}
